/*************************************************************************
	> File Name: oj-43.cpp
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年12月30日 星期三 14时35分43秒
 ************************************************************************/
#include <iostream>
#include <cstdio>
using namespace std;

int tree[1005][1005];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            scanf("%d", &tree[i][j]);
        }
    }
    for (int i = n - 1; i >= 1; --i) {
        for (int j = 1; j <= i; ++j) {
            tree[i][j] += max(tree[i + 1][j], tree[i + 1][j + 1]);
        }
    }
    printf("%d\n", tree[1][1]);
    return 0;
}
